using System;
using System.Collections.Generic;
using System.Text;

using Penult.BNet.Halo3.PlayedGames;

namespace Penult.BNet.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            //Uri gameUrl = new Uri(@"http://www.bungie.net/Stats/GameStatsHalo3.aspx?gameid=105479793"); // Two Teams
            //Uri gameUrl = new Uri(@"http://www.bungie.net/Stats/GameStatsHalo3.aspx?gameid=155897741"); // Four Teams
            //Uri gameUrl = new Uri(@"http://www.bungie.net/Stats/GameStatsHalo3.aspx?gameid=156101833"); // Slayer
            Uri gameUrl = new Uri(@"http://www.bungie.net/Stats/GameStatsHalo3.aspx?gameid=157379817"); // Two Team CTF     

            Game game = new Game(gameUrl);

            System.Console.WriteLine(game.GameType.Name + " - " + game.Map.Name);
            System.Console.WriteLine(game.Link);
            System.Console.WriteLine("Playlist: " + game.Playlist.Name);
            System.Console.WriteLine(game.GameStart.ToString());
            System.Console.WriteLine();

            if (game.Teams.Count != 0)
            {
                foreach (Team t in game.Teams)
                {
                    System.Console.WriteLine();
                    WriteTeams(t);
                    System.Console.WriteLine();

                    foreach (Player p in t.Players)
                    {
                        WritePlayers(p);
                    }

                    System.Console.WriteLine();
                }
            }
            else
            {
                foreach (Player p in game.Players)
                {
                    WritePlayers(p);
                }
            }
            
            System.Console.ReadLine();
        }

        protected static void WriteTeams(Team t)
        {
            System.Console.WriteLine("(" + t.Place + ") " + t.Name + System.Environment.NewLine +
                "(K) " + t.Kills +
                "\t(D) " + t.Deaths +
                "\t(A) " + t.Assists +
                "\t(Su) " + t.Suicides +
                "\t(B) " + t.Betrayals +
                "\t(Sc) " + t.Score);
            System.Console.WriteLine();
        }

        protected static void WritePlayers(Player p)
        {
            System.Console.WriteLine("(" + p.Place + ") " + p.Name + System.Environment.NewLine +
                "(K) " + p.Kills +
                "\t(D) " + p.Deaths +
                "\t(A) " + p.Assists +
                "\t(Su) " + p.Suicides +
                "\t(B) " + p.Betrayals +
                "\t(Sc) " + p.Score);
            System.Console.WriteLine();
        }
    }
}
